package org.mog.music.service.impl;

import entity.pojo.UserMusic;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.mog.music.mapper.UserMusicMapper;
import org.mog.music.service.IUserMusicService;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class UserMusicService implements IUserMusicService {
    private final UserMusicMapper userMusicMapper;

    /**
     * 新增记录
     *
     * @param userId
     * @param musicId
     */
    @Override
    public void insert(Long userId, Long musicId) {
        //判断是否已有记录
        UserMusic userMusic = userMusicMapper.get(musicId, userId);

        log.info("用户音乐记录：{}", userMusic);
        if (userMusic == null) {
            log.info("新增音乐用户表记录：音乐id：{}；用户id：{}", musicId, userId);
            //添加到个人音乐列表
            userMusicMapper.insert(musicId, userId);
        }
    }
}
